using UnityEngine;
using System.Collections;

public class SaveView : MonoBehaviour
{
	public SaveManager saveManager;
	public FileSaver fileSaver;
	public GameObject savePanel1;
	public GameObject savePanel2;
	public GameObject OverrideConfirm;

	private string btnYesName;

	// Use this for initialization
	void Awake ()
	{
		saveManager = GameObject.Find("SaveLoadManager").GetComponent<SaveManager>();
		fileSaver = GameObject.Find("SaveLoadManager").GetComponent<FileSaver>();
		savePanel1 = GameObject.Find("SavePanel1");
		savePanel2 = GameObject.Find("SavePanel2");

		OverrideConfirm = GameObject.Find("Overwrite");
		
		OverrideConfirm.transform.FindChild("Yes").GetComponent<UIButtonMessage>().target = GameObject.Find("SaveLoadManager");
		OverrideConfirm.transform.FindChild("Yes").GetComponent<UIButtonMessage>().functionName = "overwriteThisSaveFile";
		OverrideConfirm.transform.FindChild("No").GetComponent<UIButtonMessage>().target = GameObject.Find("SaveLoadManager");
		OverrideConfirm.transform.FindChild("No").GetComponent<UIButtonMessage>().functionName = "HideOverrideConfirm";

		OverrideConfirm.SetActive(false);
		btnYesName = "Yes";
	}
			// Update is called once per frame
	void Update ()
	{

	}

	void overwriteThisSaveFile(GameObject item)
	{
		fileSaver.saveTheFile(item.name);
		OverrideConfirm.transform.FindChild(item.name).name = "Yes";
		OverrideConfirm.SetActive(false);
		saveManager.RefreshSaveList();
	}

	void saveTheFile(Object item)
	{
		fileSaver.saveTheFile(item.name);
		saveManager.RefreshSaveList();
	}

	void ShowOverrideConfirm(GameObject item)
	{
		OverrideConfirm.SetActive(true);
		OverrideConfirm.transform.FindChild(btnYesName).name = item.name;
		btnYesName = item.name;
	}

	void HideOverrideConfirm()
	{
		OverrideConfirm.SetActive(false);
	}

	void OnLevelWasLoaded(int level)
	{

	}
}

